//
//  MFWHttpRequest.h
//  MFWSdk
//
//  Created by Song Xiaofeng on 13-7-24.
//  Copyright (c) 2013年 Mafengwo Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol ASIProgressDelegate;

typedef enum {
	
	kRequestHttpMethodGet,
	
	kRequestHttpMethodPost,
    
    kRequestHttpMethodPut,
    
    kRequestHttpMethodDelete,
	
} RequestHttpMethod;

@class MFWHttpTask;
@class MFWHttpRequest;

typedef void(^MFWRequestDidStart)(MFWHttpRequest *request);
typedef void(^MFWRequestDidChangeProgress)(MFWHttpRequest *request, long long transferSize, long long totalSize);
// simple MFWHttpRequest callback block template
// if error is nil, the http request was completed successfully
// if error is non-nil, the http request was failed. Error info contains $kMFWErrorInfo_Int_StatusCode and $kMFWErrorInfo_Str_Msg
typedef void (^MFWRequestDidComplete)(MFWHttpRequest *request, NSData* responseData, MFWJson* parsedJson, NSError* error);

@interface MFWHttpRequest : NSObject
{
    
    NSString        *_requestUrl;
    /**
     *	the request's api interface which do not contains api host
     *  if requestApi is not nil, Engine will combine api host with api interface as the request url
     */
    NSString        *_requestApi;
    
    // value->(NSString) common string parameters
    NSMutableDictionary        *_requestParams;
    // value->(NSString) request headers
    NSMutableDictionary     *_headerParams;
    
    // value->(NSData) used only for POST request
    NSMutableDictionary        *_dataParams;
    // value->(UIImage) used only for POST request
    NSMutableDictionary        *_imageParams;
    
    MFWHttpTask          *_task;
    
    RequestHttpMethod      _httpMethod;

}
@property(nonatomic, copy)NSString *requestUrl;
@property(nonatomic, copy)NSString *requestApi;
@property(nonatomic, assign)NSTimeInterval timeOutSeconds;

@property(nonatomic, strong)NSMutableDictionary *requestParams;
@property(nonatomic, strong)NSMutableDictionary *dataParams;
@property(nonatomic, strong)NSMutableDictionary *imageParams;
@property(nonatomic, strong)NSMutableDictionary *headerParams;

@property (nonatomic, copy) MFWRequestDidStart requestStartCallback;
@property (nonatomic, copy) MFWRequestDidChangeProgress requestSendProgressCallback;
@property (nonatomic, copy) MFWRequestDidChangeProgress requestDownloadProgressCallBack;
@property (nonatomic, copy) MFWRequestDidComplete requestCompleteCallback;// when request complete, if task is nil, http engine will callback on this block


@property(nonatomic, strong)MFWHttpTask *task;//maybe nil. This case indicates this is a simple MFWHttpRequest, not works with MFWDataModel, and the callback must using callback block (^requestDidComplete)


@property(nonatomic, assign)RequestHttpMethod httpMethod;
@property(nonatomic, readonly)NSString *httpMethodStr;
@property(nonatomic, assign)MFWRequestQueueType queueType;
@property(nonatomic, assign)BOOL isBackGroud;


+ (MFWHttpRequest*)dataRequest;

- (void)cancel;
@end
